package org.jsoft.comm;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class Getcon {

	/*
	 * 这是连接数据库方�?
	 * */
	public static Connection getcon(){
		Properties p=new Properties();  //创建properties的对象，为以后调用db.properties
		InputStream is=Getcon.class.getClassLoader().getResourceAsStream("comm/db.properties"); //获取制定资源的输入流
		Connection con=null;
		try {
			p.load(is);//从数据流中读取和属�?�列�?
			//用变量分别接受输入流中的各元�?
			String driver=p.getProperty("driver");
			String url=p.getProperty("url");
			String user=p.getProperty("user");
			String pass=p.getProperty("password");
			Class.forName(driver);  //建立连接，加载驱动类
			con=DriverManager.getConnection(url, user, pass); //创建连接
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	public static void close(Connection con,PreparedStatement pst,ResultSet rs){
		try {
			con.close();
			pst.close();
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
